@extends('layouts.default')
@section('css')
    <link rel="stylesheet" href="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.css')}}">
    {{--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">--}}
    {{--<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">--}}
@stop

@section('content')
    <div class="row">
        <div class="col-12">
            
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">红包管理/ <a class="text-primary" href="{{url('admin/RedBag/index')}}">红包列表</a></h3>
                </div>
                @include('layouts.message')
                <!-- /.card-header -->
                <div class="card-body">
                    <table id="example1" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>红包ID</th>
                            <th>上级用户名</th>
                            <th>上级用户用户昵称</th>
                            <th>下级用户名</th>
                            <th>下级用户用户昵称</th>
                            <th>红包金额</th>
                            <th>红包获取时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach ($lists as $list)
                        <tr>
                            <td>{{ $list['id'] }}</td>
                            <td>{{ $list['higher_user_name'] }}</td>
                            <td>{{ $list['higher_user_nickname'] }}</td>
                            <td>{{ $list['lower_user_name'] }}</td>
                            <td>{{ $list['lower_user_nickname'] }}</td>
                            <td>{{$list['total_amount']}}</td>
                            <td>{{$list['created_at']}}</td>
                        </tr>
                        @endforeach
                        </tbody>
                        <tfoot>
                        <tr>
                            <th>红包总数：</th>
                            <th>{{$count}}</th>
                            <th>红包总金额：</th>
                            <th>{{$total.'   CNY'}}</th>
                            <th>红包限制金额：</th>
                            <th><button id="red_bag_total_amount" class="btn-info">{{($red_bag_conf['conf_val']??0)}}</button>&nbsp;&nbsp;&nbsp;&nbsp;CNY</th>
                        </tr>
                        </tfoot>
                    </table>

                </div>
                <!-- /.card-body -->
            </div>
            <!-- /.card -->
        </div>
        <!-- /.col -->
        <div  id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        {{--<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>--}}
                        <h4 class="modal-title" id="gridSystemModalLabel">修改红包限额</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-inline">
                            <div class="form-group">
                                <label for="rate" id="rateLabel">红包限额：</label>
                                <input type="text" class="form-control" id="rate" name="" placeholder="{{($red_bag_conf['conf_val']??0).'   CNY'}}" style="margin-left: 10px" value="">
                            </div>
                        </form>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="modify">修改</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div><!-- /.modal -->
            <!-- /.card -->
        </div>
    </div>

@stop

@section('script')
    <script src="{{asset('admin-lte/plugins/datatables/jquery.dataTables.js')}}"></script>
    <script src="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.js')}}"></script>
    <script>
        $(function () {
            $("#example1").DataTable({
                "language"  : {
                    url :'https://cdn.datatables.net/plug-ins/1.10.19/i18n/Chinese.json',
                },
                "lengthChange": false,
                "searching": false,
            });
            $('#search').keypress(function(e){
                e = e || window.event;
               if (e.keyCode==13){
                  let search_key            = $('#search_key').val();
                  let search_val            = $('#search').val();
                  let url                   = location.href;
                  url = url.split('?')[0];
                  if (!search_key           == '' && search_val!== ''){
                      let newUrl            = `${url}?${search_key}=${search_val}`;
                      location.href          =   newUrl;
                  }else {
                      location.href          =   url;
                  }
               }
            })
        });

        $('#red_bag_total_amount').on('click',function () {
            $('#myModal').modal();
        });


        $('#modify').on('click',function (e) {
            let baseUrl     =location.origin;
            let RequsetUrl  = baseUrl +'/admin/RedBag/edit';
            let rate        = parseFloat($('#rate').val());
            if (rate>0&&!isNaN(rate)){
                let href                = `${RequsetUrl}/${rate}`;console.log(RequsetUrl);
                location.href           =   href;
            }else {
                $('#msg').html(`
                        <div class="alert alert-danger">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                红包金额必须大于等于0，小数位数最多为2位
                         </div>`
                );
            }
        })


    </script>
@stop